﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Accountant_DetailTypes : BasePage
{
    private List<TypeProviderEntity> list;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        //list = new AuditorsBLL().GetTypeProvider();
        list = new List<TypeProviderEntity>();
        list.Add(new TypeProviderEntity() { TypeProviderID = "1", TypeProviderName = "资产" });
        list.Add(new TypeProviderEntity() { TypeProviderID = "2", TypeProviderName = "负债" });

        DropDownList1.DataSource = list;
        DropDownList1.DataValueField = "TypeProviderID";
        DropDownList1.DataTextField = "TypeProviderName";
        DropDownList1.DataBind();

        DropDownList2.Items.Clear();
        DropDownList2.Items.Add(new ListItem("费用", "1"));
        DropDownList2.Items.Add(new ListItem("融资,分红", "2"));

        GridView1.DataSource = new AuditorsBLL().GetDetailTypes();
        GridView1.DataBind();
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(TextBox1.Text.Trim()))
        {
            AlertMsg("请输入名字");
            return;
        }
        if (string.IsNullOrEmpty(TextBox2.Text.Trim()))
        {
            AlertMsg("请输入英文名字");
            return;
        }

        new AuditorsBLL().CreateDetailTypes(TextBox1.Text.Trim(),TextBox2.Text.Trim(), DropDownList1.SelectedValue,DropDownList2.SelectedValue);

        TextBox1.Text = "";

        Bind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (list == null)
            {
                Bind();
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string str = e.Row.Cells[2].Text;

                e.Row.Cells[2].Text = list.First(fun => fun.TypeProviderID == str).TypeProviderName;
            }
        }

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "1")
        {
            DropDownList2.Items.Clear();
            DropDownList2.Items.Add(new ListItem("费用", "1"));
            DropDownList2.Items.Add(new ListItem("融资,分红", "2"));
        }
        else
        {
            DropDownList2.Items.Clear();
            DropDownList2.Items.Add(new ListItem("费用1", "1"));
            DropDownList2.Items.Add(new ListItem("融资,分红", "2"));
        }
    }
}